package com.three.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.three.entity.Keyboardcolor;
import com.three.mapper.KeyboardcolorMapper;
import com.three.service.KeyboardcolorService;
import com.three.vo.KeyboardcolorVO;
import com.three.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class KeyboardcolorServiceImpl implements KeyboardcolorService {
    @Autowired
    private KeyboardcolorMapper keyboardcolorMapper;

    @Override
    public R list() {
        List<Keyboardcolor> all = keyboardcolorMapper.list();
        return R.ok(all);
    }
//搜索框和展示所有
    @Override
    public R selectKeyboardcolor(Integer pageNum, Integer pageSize, KeyboardcolorVO keyboardcolorVO) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<Keyboardcolor> list = keyboardcolorMapper.selectKeyboardcolor(keyboardcolorVO);
        PageInfo<Keyboardcolor> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    @Override
    public R addKeyboardcolor(Keyboardcolor keyboardcolor) {
        int i = keyboardcolorMapper.insert(keyboardcolor);
        if (i>0) {
            return R.ok();
        }
        return R.error("添加失败");
    }
//删除
    @Override
    public R deleteKeyboardcolor(Integer keyboardcolorid) {
        int i = keyboardcolorMapper.deleteByPrimaryKey(keyboardcolorid);
        if (i>0) {
            return R.ok();
        }
        return R.error("删除失败");
    }
//修改
    @Override
    public R editKeyboardcolor(Keyboardcolor keyboardcolor) {
        int i = keyboardcolorMapper.updateByPrimaryKeySelective(keyboardcolor);
        if (i>0) {
            return R.ok();
        }
        return R.error("修改失败");
    }
}
